Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shape): Fix errors related to multi-value shape categories #4547

Merged
merged 13 commits into from
Apr 2, 2019

Conversation

kfranqueiro
Copy link
Contributor

@kfranqueiro kfranqueiro commented Mar 27, 2019

Refs #4140.

This PR changes the behavior from throwing an error and failing compilation, to warning about each encountered case and automatically falling back to using the first radius value. This is done in such a way as to avoid this problem even when multiple values are assigned at the shape variable level (i.e. centrally for small/medium/large).

I have a separate WIP branch to actually support multiple corner radii for notched-outline-related components (see the bug).

To test, assign multiple radii to the small/medium $mdc-shape-...-component-radius variable(s) in mdc-shape/_variables.scss.

Copy link
Contributor

@moog16 moog16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting errors running npm start
Screen Shot 2019-03-28 at 9 41 46 AM

@kfranqueiro
Copy link
Contributor Author

Looks like I missed replacing one instance of an old variable name. That should be fixed now.

@mdc-web-bot
Copy link
Collaborator

All 633 screenshot tests passed for commit 95ede35 vs. master! 💯🎉

moog16
moog16 previously requested changes Mar 28, 2019
packages/mdc-select/_mixins.scss Outdated Show resolved Hide resolved
packages/mdc-textfield/_mixins.scss Outdated Show resolved Hide resolved
@kfranqueiro
Copy link
Contributor Author

After merging from master after #4548 was merged, I encountered new errors. I've now resolved those, but it involved some surgery to the order of operations performed in the mdc-shape functions. The end result is that mdc-shape now better supports categories having multi-radius values (whereas our current code was clearly assuming they'd be only a single radius value).

@@ -70,39 +72,10 @@
}
}

@function mdc-shape-resolve-percentage-for-corner_($component-height, $radius) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this function lower in the file verbatim, to group internal functions together.

//
// 50% => 50
//
@function mdc-shape-strip-unit_($number) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was apparently not being used whatsoever, so I removed it.


@each $corner in $radius {
$radius-value: append($radius-value, mdc-shape-prop-corner-value_($corner));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up merging the logic of mdc-shape-prop-corner-value_ into this function after some of the finagling I did led to this function otherwise pretty much not doing anything important in itself besides validating list length.

$corner: nth($radius, $i);

@if map-has-key($mdc-shape-category-values, $corner) {
// If a category is encountered within a list of radii, apply the category's value for the corresponding corner
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior maximizes compatibility with the existing behavior which clearly expected shape categories to be applicable to individual corners (e.g. small small 0 0). This will effectively behave identically to the existing behavior in cases where a shape category is a single radius, while making list-of-radii category values actually functional.

}
}

@function mdc-shape-validate-radius-value_($radius) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function has been rewritten to emit an error, akin to the verify functions in feature-targeting, so that there's less code to write in places that call this.

@mdc-web-bot
Copy link
Collaborator

All 633 screenshot tests passed for commit 5904bd1 vs. master! 💯🎉

@kfranqueiro kfranqueiro changed the title fix(notched-outline): Warn when radius resolves to multiple values fix(shape): Fix errors related to multi-value shape categories Mar 29, 2019
@kfranqueiro kfranqueiro added this to the April 22 Release milestone Mar 29, 2019
@mdc-web-bot
Copy link
Collaborator

All 633 screenshot tests passed for commit dfe2347 vs. master! 💯🎉


@each $corner in $radius {
$radius-value: append($radius-value, mdc-shape-prop-corner-value_($corner));
@for $i from 1 through length($radius) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, why is this changed from @each to @for?

Copy link
Contributor Author

@kfranqueiro kfranqueiro Apr 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need the index to correlate between the given radius list and the fully-expanded list of radii for any categories that are referenced.

@for $i from 1 through length($radius) {
$corner: nth($radius, $i);

@if map-has-key($mdc-shape-category-values, $corner) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if small value is 4px 0 4px 0 and I apply this mixin with this value - mdc-button-shape-radius(small 0 small 0)?

I'm OK not supporting something like mdc-button-shape-radius(small 0 small 0) if that makes the implementation complex.

Copy link
Contributor Author

@kfranqueiro kfranqueiro Apr 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would result in 4px 0 4px 0. It maps each respective corner from the shape category. This also allows existing cases that expand to e.g. small small 0 0 to continue to work as-is, even if small is only a single value (it'll expand to the same value on all 4 corners).

packages/mdc-shape/_functions.scss Show resolved Hide resolved
packages/mdc-shape/_functions.scss Show resolved Hide resolved
@mdc-web-bot
Copy link
Collaborator

All 633 screenshot tests passed for commit f76d287 vs. master! 💯🎉

Copy link
Collaborator

@abhiomkar abhiomkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@mdc-web-bot
Copy link
Collaborator

@kfranqueiro kfranqueiro dismissed moog16’s stale review April 2, 2019 19:32

The build errors have been resolved.

@kfranqueiro kfranqueiro merged commit 9f79d17 into master Apr 2, 2019
@kfranqueiro kfranqueiro deleted the fix/textfield-select-shape-warn branch April 2, 2019 19:38
abhiomkar pushed a commit that referenced this pull request Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants